///<reference path="jquery.vsdoc.js" />

$.ajaxSetup({
    // Disable caching of AJAX responses
    cache: false
});

var slideshow = 0;

//AVVIO PAGINA
/*******************************************************************************/
/*                               loadPages                                     */
/*******************************************************************************/

    
function loadPages() {

    var d = $('#album-thumbs');
    newAlbum = 0;
    //--- DEFAULT
    var g = window.location.hash.replace(/_/g, " ");
    if ((g != '') && (g.indexOf('page-') < 0)) {
        var h = g.split('#');
        var i = h[1].split('/');
        var j = 0;
        //
        _gaq.push(['_setAccount', 'UA-1181516-1']);
        _gaq.push(['_trackPageview',g]);
        addfb(g);
          $('#menu .album').each(function () {
            if ($(this).children('a').text().toLowerCase() == i[0]) {
                j = 1;
                $(this).addClass('currentAlbum');
                var a = $(this).children('a').attr('href');
                d.load(a, function () {
                    imageHolder()
                    //------------------------>
                    $('#album-thumbs > ul > li > img').each(function () {
                        var e = new Image();
                        var el = $(this);
                        $(e).attr('src', el.attr('rel'));
                        $(e).load(function () {
                            el.attr('src', this.src);
                        });
                    });
               })
            }
        })
   } 
   else {
       if (g.indexOf('page-') > -1) {
           pageHandler(g.replace('#',''))
       }
       g = '';
       $('#image-holder').hide(); 
       $('#fbcomment_top').hide();
       $('.thumb-icon').hide();
       $('#next-photo').hide();
       $('#previous-photo').hide();
       $('#photo-album-wrapper').hide();
       $('#slideshow').hide();
       $('html').attr('style', 'background:#272321 url(images/dark/loading.gif) no-repeat center center;height:100%;')
        var e = new Image();
        $(e).attr('src', '../backgrounds/bk.jpg')
        $(e).load(function () {
           $('html').attr('style', 'background:#151110 url(../backgrounds/bk.jpg) no-repeat center center;height:100%;')
       });
   }

    $(document).keypress(function (e) {
        if (e.keyCode === 39) {
            var a = $('#album-thumbs ul li.current');
            var b = a.next();
            if (b.length == 0) {
                var b = $('#album-thumbs ul li:first')
            }
            callSpecPhoto(b.attr('id'))
        } else if (e.keyCode === 37) {
            var a = $('#album-thumbs ul li.current');
            var c = a.prev();
            if (c.length == 0) {
                var c = $('#album-thumbs ul li:last')
            }
            callSpecPhoto(c.attr('id'))
        }
    });
    $('li.album a').click(function () {
        if ($('#content-holder').css('display') == 'block') {
            $('#content-holder, #content-wrapper').fadeOut(700)
        }
        //------------------------>>>
        $('#image-holder').show();
        $('.thumb-icon').show();
        $('#next-photo').show();
        $('#previous-photo').show();
        $('#fbcomment_top').show();
        $('#photo-album-wrapper').show();
        $('#slideshow').show();
        $('html').attr('style', '')


        var a = $(this).parent().attr('class').split(' ');
        if (a[1] != 'currentAlbum') {
            var b = $(this).attr('href');
            //
            var tit = $(this).html()
            $('#pageAlbumTitle').html("<span style='color:red'>" + tit.substring(0, 1) + "</span><span>" + tit.substr(1) + "</span>");
            $.jGrowl("Loading Album: " + tit.substring(0, 1).toUpperCase() + tit.substr(1));
            //
            $('#menu ul li.currentAlbum').removeClass('currentAlbum');
            $(this).parent().addClass('currentAlbum');
            d.children('ul').remove();
            d.load(b, function () {
                currentScroll = 1;
                $('#album-thumbs').css({
                    left: 0
                });
                thumbsArrows();
                newAlbum = 1;
                imageHolder()
                //------------------------>
                $('#album-thumbs > ul > li > img').each(function () {
                    var e = new Image();
                    var el = $(this);
                    $(e).attr('src', el.attr('rel'));
                    $(e).load(function () {
                        el.attr('src', this.src);
                    });
                });
            })
        }
        return false
    });

    $('#previous-photo').hover(function () {
        $(this).children('div').css({
            display: 'block',
            opacity: 0
        }).stop().animate({
            opacity: 1
        }, 700)
    }, function () {
        $(this).children('div').stop().animate({
            opacity: 0
        }, 700)
    });
    $('#next-photo').hover(function () {
        $(this).children('div').css({
            display: 'block',
            opacity: 0
        }).stop().animate({
            opacity: 1
        }, 700)
    }, function () {
        $(this).children('div').stop().animate({
            opacity: 0
        }, 700)
    });
    $('#next-photo').click(function () {
        goNextPhoto();
    });
    $('#previous-photo').click(function () {
        var a = $('#album-thumbs ul li.current');
        var b = a.prev();
        if (b.length == 0) {
            var b = $('#album-thumbs ul li:last')
        }
        callSpecPhoto(b.attr('id'))

        $('#photo-album-wrapper').stop().animate({
            bottom: '-120px'
        }, {
            duration: 1600,
            easing: 'easeOutQuart'
        });
        $('.thumb-icon').stop().animate({
            width: '35px',
            height: '25px'
        }, 100)
    })

    $('#fbcomment_top').click(function () {
        $('#fbcomment').toggle("slow");
    });
    $('#content-close').click(function () {
        $('#content-wrapper').fadeOut(700);
        $('#content-holder').fadeOut(700);
    });

    //slideshow

    $('#slideshow').click(function () {
        
        if (slideshow == 0) {
            $('#slideshow').removeClass("slideshow").addClass("slideshowstop");
            $.jGrowl("Slideshow Started");
            slideshow = setInterval(function () {
                goNextPhoto();
            }, 8000);
        }
        else {
            $('#slideshow').removeClass("slideshowstop").addClass("slideshow");
            $.jGrowl("Slideshow Stopped");
            clearInterval(slideshow); slideshow = 0;
        }

    });
}
/*******************************************************************************/
/*                               goNextPhoto                                   */
/*******************************************************************************/
function goNextPhoto() {
    var a = $('#album-thumbs ul li.current');
    var b = a.next();
    var c = b.next(); //preload
    if (b.length == 0) {
        var b = $('#album-thumbs ul li:first')
    }
    callSpecPhoto(b.attr('id'))

    $('#photo-album-wrapper').stop().animate({
        bottom: '-100px'
    }, {
        duration: 600,
        easing: 'easeOutQuart'
    });
    $('.thumb-icon').stop().animate({
        width: '35px',
        height: '25px'
    }, 600)
    //precache next picture
    var e = new Image();
    $(e).attr('src', c.children("img").attr("src").replace("thumb","full"))
    $(e).load(function () {
    });
}


/*******************************************************************************/
/*                               addfb                                         */
/*******************************************************************************/
function addfb(url) {
    url = "#" + url.replace(/ /g, "_");
 
    $('#fblike').html('<fb:like href="http://www.catitti.com/main/' + url + '"  show_faces="false" layout="button_count"></fb:like>')
    if (typeof FB != "undefined") {
        FB.XFBML.parse(document.getElementById('fblike'))
    }
 
    $('#fbcomment').html('<fb:comments href="http://www.catitti.com/main/' + url + '" num_posts="2" width="500"></fb:comments>')
    if (typeof FB != "undefined") {
        FB.XFBML.parse(document.getElementById('fbcomment'))
    }
    $("#fbcommentscount").html('<fb:comments-count href="http://www.catitti.com/main/' + url + '"></fb:comments-count>');
    if (typeof FB != "undefined") {
        FB.XFBML.parse(document.getElementById('fbcommentscount'))
    }
}


/*******************************************************************************/
/*                               imageHolder                                   */
/*******************************************************************************/
function imageHolder() {
    var a = 1;
    
    $('html').removeAttr('style');

    $('#album-thumbs > ul > li').each(function () {
        if (a === 1) {
            $(this).addClass('current')
        }
        $(this).attr('id', 'albumThumb-' + a);
        a++
    });
    imageWidth = $('#image-holder > img').width();
    $(window).resize(function () {
        resizeHolder();
        imageWidth = $('#image-holder > img').width();
        centerImage(imageWidth);
        thumbsArrows()
    });
    albumThumbs();
    var b = window.location.hash.replace(/_/g, " ");
    _gaq.push(['_setAccount', 'UA-1181516-1']);
    _gaq.push(['_trackPageview', b]);
    if (b != '') {
        var c = b.split('#');
        var d = c[1].split('/');
        if (d[1] != null) {
            if (d[1] != '' && isInt(d[1]) && newAlbum === 0) {
                var e = $('#album-thumbs > ul > li:eq(' + (d[1] - 1) + ')');
                if (e.length > 0) {
                    $('#album-thumbs > ul > li.current').removeClass('current').children('span').remove();
                    e.addClass('current').append('<span class="currentArrow"></span>');
                    var f = e.children('img').attr('longdesc')
                } else {
                    var f = $('#album-thumbs > ul > li.current > img').attr('longdesc')
                }
            } else {
                var f = $('#album-thumbs > ul > li.current > img').attr('longdesc')
            }
        } else {
            var f = $('#album-thumbs > ul > li.current > img').attr('longdesc')
        }
    } else {
        var f = $('#album-thumbs > ul > li.current > img').attr('longdesc')
    }
    //

    //
    if ($('#pageAlbumTitle').html() == '') {
        $.jGrowl("Loading Album: " + d[0].substring(0, 1).toUpperCase() + d[0].substr(1));
        $('#pageAlbumTitle').html("<span style='color:red'>" + d[0].substring(0, 1).toUpperCase() + "</span><span>" + d[0].substr(1) + "</span>");
    }
    //
    loadImage(f);
    newAlbum = 0;
    $('#album-thumbs > ul > li').click(function () {
        callSpecPhoto($(this).attr('id'))
    });
    thumbsArrows();
    $('#photo-album-wrapper').hover(function () {
        $(this).stop().animate({
            bottom: 0
        }, {
            duration: 300,
            easing: 'easeOutQuart'
        });
        $('.thumb-icon').stop().animate({
            width: 0,
            height: 0
        }, 100)
    }, function () {
        $(this).stop().animate({
            bottom: '-100px'
        }, {
            duration: 300,
            easing: 'easeOutQuart'
        });
        $('.thumb-icon').stop().animate({
            width: '35px',
            height: '25px'
        }, 100)
    });
    $('#open-externally').css({
        opacity: .5
    }).hover(function () {
        $(this).stop().animate({
            opacity: 1
        }, {
            duration: 200,
            easing: 'easeOutQuart'
        });
        $(this).children('span').stop(true, true).fadeIn(200)
    }, function () {
        $(this).stop().animate({
            opacity: .5
        }, {
            duration: 300,
            easing: 'easeOutQuart'
        });
        $(this).children('span').stop(true, true).fadeOut(200)
    })
}

/*******************************************************************************/
/*                               resizeHolder                                  */
/*******************************************************************************/
function resizeHolder() {
    var a = $(window).height();
    $('#image-holder').css({
        height: (a - 84) + 'px'
    });
    var b = $(window).width();
    $('#image-holder').css({
        width: b + 'px'
    });
    var a = $(window).height();
    $('#image-holder').css({
        height: (a - 84) + 'px'
    });
    var b = $(window).width();
    $('#image-holder').css({
        width: b + 'px'
    });

}

/*******************************************************************************/
/*                               albumThumbs                                   */
/*******************************************************************************/
function albumThumbs() {
    $('#album-thumbs > ul > li span:not(#album-thumbs > ul > li.current > span)').remove();
    $('#album-thumbs > ul > li').hover(function () {
        $(this).stop().animate({
            'margin-top': '20px'
        }, {
            duration: 200,
            easing: 'easeOutQuart'
        });
        $(this).children('img').addClass('hovered')
    }, function () {
        $(this).stop().animate({
            'margin-top': '30px'
        }, {
            duration: 200,
            easing: 'easeOutQuart'
        });
        $(this).children('img').removeClass('hovered')
    });
    albumThumbCurrentArrow();
    var a = $('#album-thumbs > ul > li').length
}

/*******************************************************************************/
/*                               callSpecPhoto                                 */
/*******************************************************************************/
function callSpecPhoto(a) {
    var b = $('#album-thumbs > ul > li.current');
    var c = $('#' + a);
    if (c.attr('class') != 'current') {
        b.removeClass('current');
        c.addClass('current');
        var d = c.children('img').attr('longdesc');
        loadImage(d);
        albumThumbs()
    }
}


/*******************************************************************************/
/*                               centerImage                                   */
/*******************************************************************************/
function centerImage(a) {
    var b = $(window).width();
    var c = ($(window).height() - 94);
    var d = $('#image-holder > img').height();
    var e = $('#image-holder > img').width();
    if (d != null) {
        if (d > c) {
            if (e > b) {
                if ((e - b) > (d - c)) {
                    var f = b;
                    var g = (f / e) * d;
                    $('#image-holder > img').css({
                        height: (g - 30 ) + 'px',
                        width: f + 'px'
                    });
                    var h = (c - $('#image-holder > img').height()) / 2;

                    $('#image-holder > img').css({
                        'margin-top': (h < 20) ? '2px' : (h - 20) + 'px'
                    })
                } else if ((e - b) < (d - c)) {
                    var g = c;
                    var f = (g / d) * e;
                    $('#image-holder > img').css({
                        height: (g - 20) + 'px',
                        width: f + 'px'
                    });
                    var i = (b - $('#image-holder > img').width()) / 2;
                    $('#image-holder > img').css({
                        'margin-left': i + 'px'
                    })
                }
            } else {
                var g = c;
                var f = (g / d) * e;
                $('#image-holder > img').css({
                    height: (g - 25) + 'px',
                    width: f + 'px'
                });
                var i = (b - $('#image-holder > img').width()) / 2;
                $('#image-holder > img').css({
                    'margin-left': i + 'px'
                })
            }
        } else if (e > b) {
            var f = b;
            var g = (f / e) * d;
            $('#image-holder > img').css({
                height: (g - 25) + 'px',
                width: f + 'px'
            });
            var h = (c - $('#image-holder > img').height()) / 2;
            $('#image-holder > img').css({
                'margin-top': (h < 20) ? '2px' : (h - 20) + 'px'
            })
        } else {
            var h = (c - d) / 2;
            $('#image-holder > img').css({
                'margin-top': (h < 20) ? '2px' : (h - 20) + 'px'
            });
            var i = (b - $('#image-holder > img').width()) / 2;
            $('#image-holder > img').css({
                'margin-left': i + 'px'
            })
        }

        $('#image-holder > img').css({
            'padding-top': '4px'
        })
    }
}


/*******************************************************************************/
/*                              loadImage                                      */
/*******************************************************************************/
function loadImage(b) {
    var c = $('.currentAlbum').children('a').text().toLowerCase();
    tempIndex = 1;
    currentPhoto = 1;
    $('#album-thumbs > ul > li').each(function () {
        if ($(this).attr('class') == 'current') {
            currentPhoto = tempIndex
        }
        tempIndex++
    });
    var d = c + '/' + currentPhoto;
    window.location.hash = d.replace(/ /g, "_");
    $('#fbcomment').hide();
    addfb(d);
    resizeHolder();
    var e = new Image();
    $(e).attr('src', b);
    if (!e.complete) {
        if ($('#image-holder').children('img').length > 0) {
            $('#image-holder').children('img').stop(true, true).fadeOut(200, function () {
                $('#image-holder').removeClass('errorLoading').addClass('loading');
                $(this).remove();
                var a = new Image();
                $(a).load(function () {
                    $(this).hide();
                    $('#image-holder > img').each(function () {
                        $(this).remove();
                    })
                    $('#image-holder').removeClass('loading').append(this);
                    $(this).stop(true, true).fadeIn(800);
                    imageWidth = $(this).width();
                    centerImage(imageWidth)
                }).error(function () {
                    $('#image-holder').removeClass('loading').addClass('errorLoading')
                }).attr('src', b);
                $('#open-externally').attr('href', b)
            })
        } else {
            var e = new Image();
            $('#image-holder').removeClass('errorLoading').addClass('loading');
            $(e).load(function () {
                $(this).hide();
                $('#image-holder > img').each(function () {
                    $(this).remove();
                })
                $('#image-holder').removeClass('loading').append(this);
                $(this).stop(true, true).fadeIn(800);
                imageWidth = $(this).width();
                centerImage(imageWidth)
            }).error(function () {
                $('#image-holder').removeClass('loading').addClass('errorLoading')
            }).attr('src', b);
            $('#open-externally').attr('href', b)
        }
    } else {
        if ($('#image-holder > img').length > 0) {
            $('#image-holder > img').fadeOut(350, function () {
                $('#image-holder > img').each(function () {
                    $(this).remove();
                })
                $('#image-holder').append($(e));
                $('#image-holder > img').css({
                    opacity: 0
                }).animate({
                    opacity: 1
                }, 400);
                imageWidth = $('#image-holder > img').width();
                centerImage(imageWidth)
            });
            $('#open-externally').attr('href', b)
        } else {
            $('#image-holder').removeClass('errorLoading').append($(e));
            imageWidth = $('#image-holder > img').width();
            centerImage(imageWidth);
            $('#open-externally').attr('href', b)
        }
    }
}

/*******************************************************************************/
/*                              albumThumbCurrentArrow                         */
/*******************************************************************************/
function albumThumbCurrentArrow() {
    $('#album-thumbs> ul > li.current').append('<span class="currentArrow"></span>')
}


/*******************************************************************************/
/*                              callPreviousPhoto                              */
/*******************************************************************************/
function callPreviousPhoto() {
    var a = $('#album-thumbs ul li.current');
    var b = a.prev();
    if (b.length == 0) {
        var b = $('#album-thumbs ul li:last')
    }
    callSpecPhoto(b.attr('id'))
}


/*******************************************************************************/
/*                              tooltipHandler                                 */
/*******************************************************************************/
function tooltipHandler() {
    tooltipAdded = 0;
    tooltipClicked = 0;
    $('#image-holder').mouseenter(function () {
        var a = $('#album-thumbs ul li.current');
        var b = a.children('div.description').html();
        if (tooltipAdded === 0) {
            $('#image-tooltip').append(b);
            tooltipAdded = 1
        }
        if (tooltipClicked === 0 && b !== null) {
            $('#image-tooltip').fadeIn(200)
        }
    }).mousemove(function (e) {
        $('#image-tooltip').css({
            left: e.pageX + 'px'
        });
        $('#image-tooltip').css({
            top: (e.pageY + 40) + 'px'
        })
    }).mouseleave(function () {
        $('#image-tooltip').css({
            display: 'none'
        }).html('').append('<span></span>');
        tooltipAdded = 0
    });
    $('#image-holder').click(function () {
        var a = $('#album-thumbs ul li.current');
        var b = a.children('div.description').html();
        if (tooltipClicked === 0) {
            $('#image-tooltip').fadeOut(200);
            tooltipClicked = 1
        } else {
            if (b !== null) {
                $('#image-tooltip').fadeIn(200);
                tooltipClicked = 0
            }
        }
    })
}


/*******************************************************************************/
/*                              thumbsArrows                                   */
/*******************************************************************************/
function thumbsArrows() {
    var a = (($('#album-thumbs li').length) * (86)) + 60;
    var b = $(window).width();
    var c = (Math.ceil((a / b)) * 2) - 1;
    currentScroll = 1;
 
    $('#more-thumbs, #less-thumbs').css({
        opacity: 0
    });
    $('#more-thumbs').hover(function () {
        if (currentScroll !== c) {
            $(this).stop().animate({
                opacity: 1
            }, 200)
        }
    }, function () {
        $(this).stop().animate({
            opacity: 0
        }, 200)
    });
    $('#less-thumbs').hover(function () {
        if (currentScroll !== 1) {
            $(this).stop().animate({
                opacity: 1
            }, 200)
        } else if (currentScroll === 1) {
            $(this).css({
                'z-index': 9
            })
        }
    }, function () {
        $(this).stop().animate({
            opacity: 0
        }, 200)
    });
    $('#more-thumbs').unbind("click");
    $('#less-thumbs').unbind("click");
    $('#more-thumbs').click(function () {
        if (currentScroll < c) {
            thumbsPos = (currentScroll * (b / 2));
            $('#album-thumbs').stop().animate({
                left: '-' + thumbsPos + 'px'
            }, 400);
            $('#less-thumbs').css({
                'z-index': 15
            });
            currentScroll++
         
        }
    });
    $('#less-thumbs').click(function () {
        if (currentScroll > 1) {
            thumbsPos = ((currentScroll - 2) * (b / 2));
            $('#album-thumbs').stop().animate({
                left: '-' + thumbsPos + 'px'
            }, 400);
            currentScroll--
        }
    })
}


/*******************************************************************************/
/*                              dropDown  MENU                                 */
/*******************************************************************************/
function dropDown() {
    $("#album").superfish({  
        delay:         700,              
        animation:     {opacity:'show'}, 
        speed:         'fast'   
  }); 
}




/*******************************************************************************/
/*                              contentHandler                                 */
/*******************************************************************************/
function contentHandler() {
    var g = window.location.hash.replace(/_/g, " ");
    if ((g != '') && (g.indexOf('page-') < 0)) {
         $('#photo-album-wrapper').show();
         $('#fbcomment_top').show();
         $('#next-photo').show();
         $('#previous-photo').show();
         $('#slideshow').show();
     } 
    centerContent();
    $(window).resize(function () {
        centerContent()
    });
    $('#menu ul li').click(function () {
        return false
    });
    $('#menu ul li.page').click(function () {
        var a = $(this).children('a').attr('href');
        if (a != "#") {
            pageHandler(a);
            window.location.hash = a;
        }
    });
    $('#content-wrapper').click(function () {
        $('#content-wrapper').fadeOut(200);
        $('#content-holder').fadeOut(200);
        $('#menu ul li.page').removeClass('hovered');
    })
}
function centerContent() {
    var a = $(window).width();
    var b = $(window).height() - 80;
    var c = (a - 960) / 2;
    var d = (b - 80);
    var e = (b - 80);
    $('#content-wrapper').css({
        height: (d + 80) + 'px'
    });
    $('#content-holder').css({
        left: c + 'px',
        height: d + 'px'
    });
    $('#content-area').css({
        height: e + 'px'
    })
}




/*******************************************************************************/
/*                              pageHandlers                                   */
/*******************************************************************************/
function pageHandler(a) {
    _gaq.push(['_setAccount', 'UA-1181516-1']);
    _gaq.push(['_trackPageview', a]);

    if ($('#content-wrapper').css('display') == 'none') {
        $('#content-area').html('');
        $('#content-area').css({
            opacity: 0
        });
        $('#content-holder').addClass('loading');
        $('#content-wrapper').fadeIn(700);
        $('#content-holder').fadeIn(700);
        $('#content-area').load(a, function () {
            $('#content-holder').removeClass('loading');
            submitForm();
            $('#content-area').stop().animate({
                opacity: 1
            }, 700)
        })
    } else {
        if ($(this).attr('class') != 'page hovered') {
            $('#menu ul li.hovered').removeClass('hovered');
            $('#content-area').html('');
            $('#content-area').css({
                opacity: 0
            });
            $('#content-holder').addClass('loading');
            $('#content-area').load(a, function () {
                $('#content-holder').removeClass('loading');
                $('#content-area').stop().animate({
                    opacity: 1
                }, 700);
            });
            submitForm()
        } else {
            $('#content-wrapper').fadeOut(700);
            $('#content-holder').fadeOut(700);
        }
    }
    return false
}

/*******************************************************************************/
/*                              isInt                                          */
/*******************************************************************************/
function isInt(x) {
    var y = parseInt(x);
    if (isNaN(y)) return false;
    return x == y && x.toString() == y.toString()
} (function ($) {
    $.fn.hoverIntent = function (f, g) {
        var c = {
            sensitivity: 7,
            interval: 100,
            timeout: 0
        };
        c = $.extend(c, g ? {
            over: f,
            out: g
        } : f);
        var d, cY, pX, pY;
        var h = function (a) {
            d = a.pageX;
            cY = a.pageY
        };
        var i = function (a, b) {
            b.hoverIntent_t = clearTimeout(b.hoverIntent_t);
            if ((Math.abs(pX - d) + Math.abs(pY - cY)) < c.sensitivity) {
                $(b).unbind("mousemove", h);
                b.hoverIntent_s = 1;
                return c.over.apply(b, [a])
            } else {
                pX = d;
                pY = cY;
                b.hoverIntent_t = setTimeout(function () {
                    i(a, b)
                }, c.interval)
            }
        };
        var j = function (a, b) {
            b.hoverIntent_t = clearTimeout(b.hoverIntent_t);
            b.hoverIntent_s = 0;
            return c.out.apply(b, [a])
        };
        var k = function (e) {
            var p = (e.type == "mouseover" ? e.fromElement : e.toElement) || e.relatedTarget;
            while (p && p != this) {
                try {
                    p = p.parentNode
                } catch (e) {
                    p = this
                }
            }
            if (p == this) {
                return false
            }
            var a = jQuery.extend({}, e);
            var b = this;
            if (b.hoverIntent_t) {
                b.hoverIntent_t = clearTimeout(b.hoverIntent_t)
            }
            if (e.type == "mouseover") {
                pX = a.pageX;
                pY = a.pageY;
                $(b).bind("mousemove", h);
                if (b.hoverIntent_s != 1) {
                    b.hoverIntent_t = setTimeout(function () {
                        i(a, b)
                    }, c.interval)
                }
            } else {
                $(b).unbind("mousemove", h);
                if (b.hoverIntent_s == 1) {
                    b.hoverIntent_t = setTimeout(function () {
                        j(a, b)
                    }, c.timeout)
                }
            }
        };
        return this.mouseover(k).mouseout(k)
    }
})(jQuery);
(function (a) {
    a.fn.aeImageResize = function (b) {
        var c = jQuery.extend({
            height: 9,
            width: 9
        }, b);
        this.each(function () {
            var d = c.height,
                g = c.width,
                i = a(this).height(),
                f = a(this).width(),
                h = Math.ceil,
                e = Math.floor;
            if (i >= f) {
                g = e(h(f / i * d))
            } else {
                d = e(h(i / f * g))
            }
            a(this).attr({
                height: d,
                width: g
            })
        })
    }
})(jQuery);